<?php

// ========== Init section ==========
// Allow inclusion for the other files
define('INCLUDE', true);

// Configuration file see doc inside
require_once 'config.php';

// Database file see doc inside (based on SQLite v2)
require_once CORE_DIRECTORY.OS_PATH_SEPARATOR.'database.php';

// Database object is instanced here as we'll always need it,
// it will be used as a global variable to pass-through multiple instantiations
$DB = new Database(DATABASE);

$availableActions = array(
	'deleteMeta',
);

$redirect = '';
if(!empty($_REQUEST['action']) && in_array($_REQUEST['action'], $availableActions))
{
	if($_REQUEST['action'] == 'deleteMeta')
	{
		if(isset($_REQUEST['id'], $_REQUEST['type']))
		{
			$id = (int)$_REQUEST['id'];
			$type = (int)$_REQUEST['type'];
			require_once CORE_DIRECTORY.OS_PATH_SEPARATOR.'baseMetadata.php';
			BaseMetadata::deleteMeta($type, $id);
			$redirect = '?type='.$type;
		}
	}
}
else
{
	throw new Exception('No valid action to do');
}

if(isset($_REQUEST['ajax']))
{
	die(json_encode('ok'));
}
else
{
	redirect('index.php'.$redirect);
}

exit;

